<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑用户 - AI面试系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container">
        <a class="navbar-brand" href="#">AI面试系统 - 用户管理</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <span class="nav-link">欢迎，[[${#authentication?.principal?.username ?: '管理员'}]]</span>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/admin/users}">用户管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/interview}">返回系统</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/logout}">退出登录</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card shadow">
                <div class="card-header bg-warning text-dark">
                    <h4 class="mb-0"><i class="bi bi-pencil"></i> 编辑用户</h4>
                </div>
                <div class="card-body">
                    <!-- 错误消息 -->
                    <div th:if="${errorMessage}" class="alert alert-danger">
                        [[${errorMessage}]]
                    </div>

                    <form th:action="@{/admin/users/edit/{id}(id=${user.id})}" method="post">
                        <div class="mb-3">
                            <label for="username" class="form-label">用户名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="username" name="username" 
                                   th:value="${user.username}" required>
                            <div class="form-text">用户名必须唯一，用于登录系统</div>
                        </div>

                        <div class="mb-3">
                            <label for="fullName" class="form-label">全名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="fullName" name="fullName" 
                                   th:value="${user.fullName}" required>
                        </div>

                        <div class="mb-3">
                            <label for="email" class="form-label">邮箱 <span class="text-danger">*</span></label>
                            <input type="email" class="form-control" id="email" name="email" 
                                   th:value="${user.email}" required>
                            <div class="form-text">邮箱必须唯一，用于找回密码</div>
                        </div>

                        <div class="mb-3">
                            <div class="alert alert-info">
                                <i class="bi bi-info-circle"></i>
                                <strong>注意：</strong> 要修改密码，请使用 <a th:href="@{/admin/users/change-password/{id}(id=${user.id})}" class="alert-link">修改密码</a> 功能。
                            </div>
                        </div>

                        <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                            <a th:href="@{/admin/users}" class="btn btn-secondary me-md-2">取消</a>
                            <button type="submit" class="btn btn-warning">更新用户</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
